<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        列表
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../css/main.css" media="all">
    <script type="text/javascript" src="../../../lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../../../css/bootstrap.css">
    <link rel="stylesheet" href="../../../lib/layui/css/layui_2.5.7.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .layui-table-page select {
            height: 22px;
        }
    </style>
</head>

<body>
<div>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a><cite>首页</cite></a>
            <a><cite>财务业务</cite></a>
            <a><cite>票据流水</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
           href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                            style="line-height:30px">ဂ</i></a>
    </div>

    <div id="app" class="row">
        <div style="margin-left: 17%" class="col-xs-6 col-sm-4 col-md-3">
            <section class="panel">
                <div class="symbol bgcolor-blue"><i class=" iconfont icon-dashaxiaoqudizhi01"></i>
                </div>
                <div class="value tab-menu" bind="1">
                    <a href="javascript:;" data-url="user-info.html" data-parent="true" data-title="本月开票总额（元）"><i
                            class="iconfont " data-icon=""></i>
                        <h1>{{statistics.kaiAmountOfThisMonth == null ? 0 : statistics.kaiAmountOfThisMonth}}</h1>
                    </a>
                    <a href="javascript:;" data-url="user-info.html" data-parent="true" data-title="本月开票总额（元）"> <i
                            class="iconfont " data-icon=""></i><span>本月开票总额（元）</span></a>
                </div>
            </section>
        </div>
        <div style="margin-left: 12%" class="col-xs-6 col-sm-4 col-md-4">
            <section class="panel">
                <div class="symbol bgcolor-blue"><i class="iconfont icon-dashaxiaoqudizhi01"></i>
                </div>
                <div class="value tab-menu" bind="1">
                    <a href="javascript:;" data-url="user-info.html" data-parent="true" data-title="本月收票总额（元）"> <i
                            class="iconfont " data-icon=""></i>
                        <h1>{{statistics.shouAmountOfThisMonth == null ? 0 : statistics.shouAmountOfThisMonth}}</h1>
                    </a>

                    <a href="javascript:;" data-url="user-info.html" data-parent="true" data-title="本月收票总额（元）"> <i
                            class="iconfont " data-icon=""></i><span>本月收票总额（元）</span></a>
                </div>
            </section>
        </div>

    </div>

    <div class="main_box">
        <div class="panel-heading">
            <ul class="nav nav-tabs" id="navTabs">
                <li class=""><a class="receivePane" data-tab="" href="billflow.html">票据流水</a></li>
                <li class=""><a class="payPane" data-tab="" href="billflow_kai.html">开票流水</a></li>
                <li class=""><a class="borrowPane" data-tab="" href="billflow_shou.html">收票流水</a></li>
                <li class="active"><a class="repayPane" data-tab="" href="billflow_cancel.html">已作废列表</a></li>
                <li style="float: right;width: 162px" class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
                       aria-expanded="false">添加票据<span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="javascript:void(0)" onclick="admin_add('添加开票流水','billing.html')">添加开票流水</a></li>
                        <li role="separator" class="divider"></li>
                        <li><a href="javascript:void(0)"
                               onclick="admin_add('添加收票流水','ticket_collection.html')">添加收票流水</a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>

    <form class="layui-form x-center">
        <div class="layui-form-pane" style="margin-top: 15px;">
            <div class="layui-form-item" style="padding-left: 7%">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" class="layui-input" name="name" placeholder="名称">
                </div>
                <label class="layui-form-label">纳税人识别号</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" class="layui-input" name="taxpayerIdentificationNumber" placeholder="纳税人识别号">
                </div>
                <label class="layui-form-label">地址电话</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" class="layui-input" name="addressAndTelephoneNumber" placeholder="地址电话">
                </div>
                <div style="clear: both"></div>
                <label class="layui-form-label">票据类型</label>
                <div class="layui-input-inline">
                    <select name="billType" lay-search="">
                        <option value="">---</option>
                    </select>
                </div>

                <label class="layui-form-label">添加时间</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  class="layui-input" placeholder="开始日" name="start" id="start">
                </div>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  class="layui-input" placeholder="截止日" name="start" id="end">
                </div>
                <div class="layui-input-inline layui-show-xs-block">
                    <button class="layui-btn" type="button" lay-filter="sreach" data-type="reload"
                            onclick="reload()">
                        <i class="layui-icon">&#xe615;</i></button>
                </div>

            </div>
        </div>
    </form>

    <div>
        <span style="display: inline-block;margin-left: 2%;color: red;font-size: 20px;"><b>开票总额：<span id="searchKaiMoney">-</span> 元, 收票总额：<span id="searchShouMoney">-</span> 元</b></span>
    </div>
    <div class="layui-card-body">

        <table class="layui-table" id="test" lay-filter="test">
        </table>
    </div>
    <br><br><br><br><br><br>
</div>
</body>


<script type="text/javascript" src="../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../js/pub.js"></script>
<script type="text/javascript" src="../../../lib/layui/layui2.5.7.js"></script>
<script type="text/javascript" src="../../../js/vue.min.js"></script>
<!-- <script src="lib/layui/layui.js" charset="utf-8"></script> -->
<script src="../../../js/x-layui.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script>
    layui.use(['laydate', 'element', 'laypage', 'layer', 'form'], function () {
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element;//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        var form = layui.form;
        okLoading.close($);
    });
</script>


<script>

    layui.use(['laydate', 'form'],
        function () {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                trigger: 'click',
                type: 'datetime',
                elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                trigger: 'click',
                type: 'datetime',
                elem: '#end' //指定元素
            });
        });


    layui.use('table', function () {
        table = layui.table;
        //方法级渲染
        var t1 = table.render({
            elem: '#test',
            url: $baseUrl + 'billFlow/findBillFlowList',
            where: {
                userId: $userId,
                status: '1',
            },
            headers: {
                token: $token
            }
            , toolbar: '#toolbarDemo',

            // toolbar: true,
            cols: [
                [
                    {
                        field: 'name',
                        title: '名称',
                        fixed: 'left',
                        width: '12%'
                    },
                    {
                        field: 'nature',
                        title: '性质',
                        width: '6%',
                        fixed: 'left',
                        templet(item) {
                            if (item.nature === '开票') {
                                return '<span style="color: #3f51b5">开票</span>';
                            } else if (item.nature === '收票') {
                                return '<span style="color: green">收票</span>';
                            } else if (item.nature == undefined) {
                                return '';
                            } else {
                                return item.nature;
                            }

                        }
                    },
                    {
                        field: 'taxpayerIdentificationNumber',
                        title: '纳税人识别号',
                        width: '15%'
                    },
                    {
                        field: 'addressAndTelephoneNumber',
                        title: '地址电话',
                        width: '15%'
                    },
                    {
                        field: 'bankAndAccountNumber',
                        title: '开户行和账号',
                        width: '15%'
                    },
                    {
                        field: 'contactInformation',
                        title: ' 联系信息',
                        width: '15%'
                    },
                    {
                        field: 'billType',
                        title: '票据类型',
                        width: '8%',
                        fixed: 'left',
                    },
                    {
                        field: 'faceValue',
                        title: '票面金额',
                        width: '8%',
                        fixed: 'left',
                    },
                    {
                        field: 'billingDate',
                        title: '开票日期',
                        width: '15%'
                    },
                    {
                        field: 'taxPoint',
                        title: '税点',
                        width: '15%'
                    },
                    {
                        field: 'faceTax',
                        title: '票面税额',
                        width: '15%'
                    },
                    {
                        field: 'associatedCredentials',
                        title: '关联凭据',
                        width: '15%'
                    },
                    {
                        field: 'associatedCredentialsId',
                        title: '关联凭据Id',
                        width: '15%'
                    },
                    {
                        field: 'remark',
                        title: '摘要说明',

                    },
                    {
                        field: 'billAttachment',
                        title: '票据附件',
                        width: '15%',
                        templet: function (e) {
                            if (e.billAttachment !== '') {
                                var str = '';
                                var arr = e.billAttachment.split(",");
                                for (let i = 0; i < arr.length; i++) {
                                    str += '<img style="width: 25px;height: 25px;" ' +
                                        'onclick="window.open($baseUrl + \'other/viewUploadFile?id=' + arr[i] + '\')" ' +
                                        'src=' + $baseUrl + 'other/viewUploadFile?id=' + arr[i] + '>';
                                }
                                return str;
                            } else {
                                return '空'
                            }

                        },
                    },
                    {
                        field: 'pictureOfReceipt',
                        title: '签收回执图片',
                        width: '15%',
                        templet: function (e) {
                            if (e.pictureOfReceipt !== '') {
                                var str = '';
                                var arr = e.pictureOfReceipt.split(",");
                                for (let i = 0; i < arr.length; i++) {
                                    str += '<img style="width: 25px;height: 25px;" ' +
                                        'onclick="window.open($baseUrl + \'other/viewUploadFile?id=' + arr[i] + '\')" ' +
                                        'src=' + $baseUrl + 'other/viewUploadFile?id=' + arr[i] + '>';
                                }
                                return str;
                            } else {
                                return '空'
                            }

                        },
                    },
                ]
            ],
            request: {
                pageName: 'pageNum', //页码的参数名称，默认：page
                limitName: 'pageSize',
            },
            response: {
                statusName: 'code' //规定数据状态的字段名称，默认：code
                ,
                statusCode: 0 //规定成功的状态码，默认：0
                ,
                msgName: 'msg' //规定状态信息的字段名称，默认：msg
                ,
                countName: 'total' //规定数据总数的字段名称，默认：count
                ,
                dataName: 'data.content', //规定数据列表的字段名称，默认：data
            },
            id: 'test',
            page: true,
            height: 'auto',
            even: true,
            done: function (res, curr, count) {
                //是否有权限或权限是否失效
                // authorizeState();
                $("#searchShouMoney").text(res.data.shou);
                $("#searchKaiMoney").text(res.data.kai);
                vm.statisticsFun();
            }
        });


        //修改状态
        let form = layui.form;

        //查发票类型
        let request = {
            url: 'dictionary/findDataDictionaryValue',
            data: {
                userId: $userId,
                label: 'BILL_TYPE'
            },
            method: "POST",
        };
        sendRequest(request, (res) => {
            // console.log(res);
            let billType = res.data;
            $.each(billType, function (index, item) {
                let opt = $("<option value=" + item + ">" + item + "</option>");
                $("select[name=billType]").append(opt);
                form.render('select');
            });
        });


        //监听工具条
        table.on('tool(test)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            let data = obj.data; //获得当前行数据
            let layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if (layEvent === 'del') { //删除
                layer.confirm('是否确认删除 【' + data.name + '】 ？', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    let request = {
                        url: "billFlow/delBillFlow/" + data.id,
                        data: {
                            userId: $userId,
                        },
                        method: "DELETE",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.msg("删除成功", {
                                icon: 1
                            });
                            t1.reload();
                        } else {
                            layer.msg("删除失败，请稍后再试！", {
                                icon: 5
                            });
                        }
                    });
                    layer.close(index);
                });
            } else if (layEvent === 'view') { //编辑
                if (data.nature === "开票") {
                    admin_add('编辑', 'billing.html?recordId=' + data.id)
                } else {
                    admin_add('编辑', 'ticket_collection.html?recordId=' + data.id)
                }

            } else if (layEvent === 'zf') { //作废

                layer.confirm('是否确认作废 【' + data.name + '】 ？', {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    let request = {
                        url: "billFlow/editBillFlowStatus",
                        data: {
                            userId: $userId,
                            recordId: data.id
                        },
                        method: "POST",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.msg("作废成功", {
                                icon: 1
                            });
                            t1.reload();
                        } else {
                            layer.msg("作废失败，请稍后再试！", {
                                icon: 5
                            });
                        }
                    });
                    layer.close(index);
                });

            }
        });

    });

    function reload(value) {
        table.reload('test', {
            where: {
                name: $("input[name=name]").val(),
                taxpayerIdentificationNumber: $("input[name=taxpayerIdentificationNumber]").val(),
                addressAndTelephoneNumber: $("input[name=addressAndTelephoneNumber]").val(),
                billType: $("select[name=billType]").val(),
                start: $("input[name=start]").val(),
                end: $("input[name=end]").val(),
            }
        });
    }

    function admin_add(title, url, w, h) {
        x_admin_show(title, url, w, h);
    }
</script>

<script>
    var vm = new Vue({
        el: "#app",
        data: {
            statistics: {
                kaiAmountOfThisMonth: null,
                shouAmountOfThisMonth: null,
            }
        },
        mounted() {
            this.statisticsFun();
        },
        methods: {
            statisticsFun() {
                let request = {
                    url: 'billFlow/findDataStatistical',
                    data: {
                        userId: $userId,
                    },
                    method: "POST",
                };
                sendRequest(request, (res) => {
                    this.statistics = res.data
                });
            }
        }

    });

</script>


</html>
